//
//  GifCell.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/18.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "GifCell.h"

@implementation GifCell
- (void)dealloc
{
    [_nameLable release];
    [_title release];
    [_str release];
    [_width release];
    [_heigth release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.img = [[UIImageView alloc]init];
        _img.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_img];
        [_img release];
        
        self.nameLable = [[UILabel alloc]init];
       // _nameLable.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_nameLable];
        [_nameLable release];
        
        self.title = [[UILabel alloc]init];
        //_title.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_title];
        [_title release];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat W = self.contentView.frame.size.width;
    NSNumber *screenW = [NSNumber numberWithFloat:W];
    double h = [[self class]heightWithImage:_width.stringValue WithHeight:_heigth.stringValue withScreenWidth:screenW];
    //imgview
    _img.frame = CGRectMake(0, 0, self.contentView.frame.size.width, h);
    _img.center = self.contentView.center;
    
    _nameLable.frame = CGRectMake(5, _img.frame.origin.y + _img.frame.size.height, self.contentView.frame.size.width, 20);
    _nameLable.textColor = [UIColor grayColor];
    _nameLable.font = [UIFont systemFontOfSize:14];
    _title.frame = CGRectMake(5, _nameLable.frame.origin.y + _nameLable.frame.size.height + 5, self.contentView.frame.size.width, 40);
//    _title.textColor = [UIColor grayColor];
    _title.font = [UIFont systemFontOfSize:14];
    _title.numberOfLines = 0;
    
    
}
//图片高度自适应
+(double)heightWithImage:(NSString *)width WithHeight:(NSString *)height withScreenWidth:(NSNumber *)ww
{
    CGFloat screenW = ww.floatValue;
    CGFloat w = width.floatValue;
    CGFloat h = height.floatValue;
    double newh =  (double)(h * screenW / w);
    return  newh;
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
